<?php require_once "menu.php"; ?>
<table width="100%" class="menubar" cellpadding="0" cellspacing="0" border="0">
    <tr>
        <td class="menudottedline" width="40%"><div class="pathway"></div></td>
        <td class="menudottedline" align="right">
            <table cellpadding="0" cellspacing="0" border="0" id="toolbar">
                <tr height="60" valign="middle" align="center">
                    <td>
                        <a class="toolbar" href="#" id="addlink">
                        <?php echo $html->image('admin/copy_f2.png', array('align' => 'middle', 'border' => 0)); ?><br>Add
                        </a>
                    </td>
                    <td>
                        <a class="toolbar" href="#" id="deletelink">
                        <?php echo $html->image('admin/cancel_f2.png', array('align' => 'middle', 'border' => 0)); ?><br>Delete
                        </a>
                    </td>
                    <td>
                        <a class="toolbar" href="#">
                        <?php echo $html->image('admin/help_f2.png', array('align' => 'middle', 'border' => 0)); ?><br>Help
                        </a>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
<br>
<br>
<div align="center" class="centermain">
    <div class="main">

        <table class="adminheading">
            <tr>
                <th class="info" rowspan="2" nowrap>Manage SMTP Settings</th>
            </tr>
        </table>

        <table class="adminform" style="width: 100%;">
            <tr>
                <td width="80%" valign="top">

                    <form id="adminForm" name="adminForm" action="<?php echo $html->url('/smtp/smtpmgnt'); ?>" method="post">
                    <div class="error"></div>
                    <table class="adminlist" cellpadding="20" style="width: 100%">
                    	<tr>
                    		<th colspan="5">SMTP List</th>
                    	</tr>
                        <tr bgcolor="#ae1d1d">
                            <td width="5%">&nbsp;</td>
                            <td width="20%" class="subheader" align="left"><?php echo $paginator->sort('Host', 'host', array('style' => 'color: #ffffff;')); ?></td>
                            <td width="25%" class="subheader" align="left"><?php echo $paginator->sort('User', 'uid', array('style' => 'color: #ffffff;')); ?></td>
                            <td width="15%" class="subheader" align="left"><?php echo $paginator->sort('Date Added', 'date_added', array('style' => 'color: #ffffff;')); ?></td>
                            <td width="%">&nbsp;</td>
                        </tr>

                        <?php
                         if ($smtps) {
                            foreach($smtps as $k => $v){
                                $color = (($k/2) == round($k/2)) ? "#efefef" : "#ffffff";
                         ?>
                        <tr bgcolor="<?php echo $color; ?>">
                            <td><input type="checkbox" id="nt<?php echo $k; ?>" name="data[row][id][]" value="<?php echo $v['SmtpSetting']['smtpId']; ?>" onclick="isChecked(this.checked);"></td>
                            <td align=""><?php echo $html->link($v['SmtpSetting']['host'], '/smtp/smtpedit/'.$v['SmtpSetting']['smtpId'])?></td>
                            <td><?php echo $v['SmtpSetting']['uid']?></td>
                            <td><?php echo date('M d, Y', strtotime($v['SmtpSetting']['date_added']))?></td>
                            <td>
                                <?php
                                 if ($v['SmtpSetting']['active'] == 1) {
                                     echo "{Default}";
                                 } else {
                                 ?>
                                <a href="#" onclick="javascript: document.getElementById('flag').value='makedefault'; document.getElementById('smtpid').value=<?php echo $v['SmtpSetting']['smtpId']?>; document.adminForm.submit(); ">
                                <?php echo $html->image('admin/publish_g.png', array('border' => 0, 'alt' => '')); ?>
                                </a>
                                <label>Make Default</label>
                                <?php
                                 }
                                 ?>
                            </td>
                        </tr>
                        <?php
                            }
                         }
                         ?>

                        <tr>
                            <td colspan="5" align="center">
                                <div class="pagination">
                                <?php
                                 echo $paginator->prev()."&nbsp;";
                                 echo $paginator->numbers();
                                 echo "&nbsp;".$paginator->next();
                                 ?>
                                </div>
                            </td>
                        </tr>
                    </table>
                    <input type="hidden" name="boxchecked" value="0" />
                    <input type="hidden" id="flag" name="data[flag]" />
                    <input type="hidden" id="smtpid" name="data[smtpid]" />
                    </form>

                </td>
            </tr>
        </table>

    </div>
</div>

<script type='text/javascript'>
$(document).ready(function() {
    // submit form when delete
    $("#deletelink").click(function() {
        if (confirm('Delete selected smtp settings?')) {
            $("#flag").val("delete");
            $("#adminForm").submit();
        }
    });

    /*$("#defaultlink").click(function() {
        if (confirm('Make the selected smtp settings default?')) {
            $("#flag").val("default");
            $("#adminForm").submit();
        }
    });*/

    $("#addlink").click(function() {
        window.location = '<?php echo $html->url("/smtp/smtpadd");?>';
    });
});
</script>